﻿using HAF.DBUtility;
using HAF.LogUtility;
using MediaTransfer.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MediaTransfer.Helper
{
    public class MediaDbHelper : DbBaseHelper
    {
        private static MediaDbHelper _dbhelper = null;
        private MediaDbHelper() { }

        public static MediaDbHelper GetInstance()
        {
            return _dbhelper ?? (_dbhelper = new MediaDbHelper());
        }

        /// <summary>
        /// 获取发布工单
        /// </summary>
        /// <param name="taskName">任务名</param>
        /// <returns></returns>
        public List<MediaTaskDto> GetTaskData(string taskName, string cpName)
        {
            var db = GetDB();
            string sql = string.Empty;
            try
            {
                db.Begin();
                sql = string.Format("select ID, FootageFileName As FileName, FileSeviceCode, TargetCodes, TargetNames, SourceRelativePath as SrcPath, RelativePath as DestPath, " +
                    "Status from media_distributefile where TaskName = '{0}' and CreationTime > '2024-12-01' and FileSeviceCode = '{1}' and Status = '完成' ORDER BY FootageFileName;", 
                    taskName, cpName);
                LogHelper.WriteDebugLog(sql);
                List<MediaTaskDto> outDatas = db.Query<MediaTaskDto>(sql);
                db.Commit();

                return outDatas;
            }
            catch (Exception ex)
            {
                
                LogHelper.WriteErrorLog(string.Format("方法{0}发生异常：{1}", System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString()));
                return null;
            }
        }
    }
}
